package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogDayLogin;
import com.yanqu.road.entity.log.LogLogin;
import com.yanqu.road.entity.log.LogOnlineNum;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogLoginDaoImpl extends TempDao {

    public boolean addLogOnlineNumList(List<LogOnlineNum> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getServerDb());
        String sql = "INSERT INTO t_s_online_data(serverId,userCount,time) VALUES(?,?,?)";

        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogOnlineNum info : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, info.getServerId()));
            para.put(i++, new DbParameter(Types.INTEGER, info.getCount()));
            para.put(i++, new DbParameter(Types.BIGINT, info.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogDayLoginList(List<LogDayLogin> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getServerDb());
        String sql = "INSERT INTO t_s_day_login(userId,time,registerTime,serverId) VALUES(?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogDayLogin info : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, info.getUserId()));
            para.put(i++, new DbParameter(Types.BIGINT, info.getTime()));
            para.put(i++, new DbParameter(Types.BIGINT, info.getRegisterTime()));
            para.put(i++, new DbParameter(Types.BIGINT, info.getServerId()));

            mapList.add(para);
        }

        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


}
